def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def closest_prime_number(s):
    words = s.split()
    if len(words) != 3:
        return "Wrong input"
    try:
        number = int(''.join(str({'zero':0, 'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8, 'nine':9}[word]) for word in words))
        if 100 <= number <= 999:
            lower = number - 1
            upper = number + 1
            while not is_prime(lower) and not is_prime(upper):
                lower -= 1
                upper += 1
            if is_prime(lower):
                return lower
            else:
                return upper
        else:
            return "Wrong input"
    except KeyError:
        return "Wrong input"


string = input()

print(closest_prime_number(string))
